package com.hznc.wcs.flowable.candidate;


import com.hznc.wcs.enums.BpmTaskCandidateStrategyEnum;
import com.hznc.wcs.service.bpm.BpmProcessInstanceService;
import jakarta.annotation.Resource;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Set;

@Component
public class BpmTaskCandidateStartUserStrategy implements BpmTaskCandidateStrategy{

    @Resource
    @Lazy // 延迟加载，避免循环依赖
    private BpmProcessInstanceService processInstanceService;


    @Override
    public BpmTaskCandidateStrategyEnum getStrategy() {
        return BpmTaskCandidateStrategyEnum.START_USER;
    }

    @Override
    public void validateParam(String param) {

    }

    @Override
    public Set<String> calculateUsers(DelegateExecution execution, String param) {
        ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId());
        String startUserId = processInstance.getStartUserId();
        HashSet<String> result = new HashSet<>();
        result.add(startUserId);
        return result;

    }
}
